package com.jiyici.network;

import jiyici.Constant.ErrorCode;
import android.util.SparseIntArray;

import com.jiyici.R;

public class Errors {

    public static int ERROR_ACTION_NOT_SUPPORTED = 1000;
    public static int ERROR_NO_REQUEST_DATA = 1001;
    public static int ERROR_INVALID_DATA_FORMAT = 1002;
    public static int ERROR_EMAIL_EXIST = 1003;
    public static int ERROR_LOGIN_FAILED = 1004;
    public static int ERROR_NOT_AUTHENTICATED = 1005;
    public static int ERROR_SYSTEM_ERROR = 1006;

    private static SparseIntArray errors = new SparseIntArray();
    static {
        errors.put(ErrorCode.ERROR_ACTION_NOT_SUPPORTED, R.string.error_action_not_supported);
        errors.put(ErrorCode.ERROR_NO_REQUEST_DATA, R.string.error_no_request_data);
        errors.put(ErrorCode.ERROR_INVALID_DATA_FORMAT, R.string.error_invalid_data_format);
        errors.put(ErrorCode.ERROR_EMAIL_EXIST, R.string.error_email_exist);
        errors.put(ErrorCode.ERROR_LOGIN_FAILED, R.string.error_login_failed);
        errors.put(ErrorCode.ERROR_NOT_AUTHENTICATED, R.string.error_not_authenticated);
        errors.put(ErrorCode.ERROR_SYSTEM_ERROR, R.string.error_system_error);
    }

    public static int getErrorString(int errorCode) {
        int errorResourceId = errors.get(errorCode, R.string.error_system_error);
        return errorResourceId == 0 ? R.string.error_unknown : errorResourceId;
    }

}
